package com.eln.countdown.service.pojo;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.Timer;

/**
 * @author lenigeet
 *
 */
public class Countdown extends AbstractAction {

	private static final long serialVersionUID = 535188068343408612L;
	private int time;
	private Timer timer;
	private Collection<Object> values = new ArrayList<Object>();

	public Countdown() {
		time = 0;
		timer = new Timer(1000, this);
	}

	public Countdown(int time) {
		this.time = time;
		timer = new Timer(1000, this);
	}

	public boolean isStarted() {
		return timer.isRunning();
	}

	public void start() {
		timer.start();		
	}

	public void stop() {
		timer.stop();
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (this.isStarted()) {
			if (time > 0) {
				time--;
			} else {
				this.stop();
			}
		}
	}
	
	public void test() {
		List<Object> test = (List<Object>)values;
	}
}
